/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-07-09
 * Time: 23:58
 */
public class Solution {
    import java.util.*;
    /*
    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }*/

        public ListNode ReverseList(ListNode head){
            Stack<ListNode>   stack=new Stack<>();//定义一个栈
            while(head!=null){
                stack.push(head);
                head=head.next;
            }
            if(stack.isEmpty())
                return  null;
            ListNode  node=stack.pop();
            ListNode    dummy=node;
            while(!stack.isEmpty()){
                ListNode   retNode=stack.pop();
                node.next=retNode;
                node=node.next;
            }

            node.next=null;
            return dummy;


        }
    }
//问题是主函数咋写
